package com.atguigu02.method_lifecycle;

/**
 * @author lhl
 * @date 2025/4/2 16:01
 */
public class PrintNumberTest {

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 100; i++) {

//                try {
//                    Thread.sleep(1000);
//                } catch (InterruptedException e) {
//                    throw new RuntimeException(e);
//                }

                if (i % 2 == 0) {
                    System.out.println(Thread.currentThread().getName() + "：" + i);
                }

//                if (i % 20 == 0) {
//                    Thread.yield();
//                }
            }
        });
        t1.setName("子线程");
        t1.start();

        Thread.currentThread().setName("主线程");
        for (int i = 0; i < 100; i++) {
            if (i % 2 == 0) {
                System.out.println(Thread.currentThread().getName() + "===" + i);
            }


//            if (i == 20) {
//                try {
//                    t1.join();
//                } catch (InterruptedException e) {
//                    throw new RuntimeException(e);
//                }
//            }

        }

//        System.out.println("子线程是否存活？"+t1.isAlive());

    }
}
